﻿using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
namespace INTEX.DataBase.Tools
{
    public partial class INTEXDBC
    {
        public void MapQVW_ZUTEI(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveQVW_ZUTEI(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet Result = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            Result = QueryQVW_ZUTEI(dwData);
            if (Result.Tables.Count > 0)
            {
                tbLocal = Result.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }

            MapQVW_ZUTEI(ref dwLocal, dwData);

            if (!flgExist)
            {
                InsertQVW_ZUTEI(dwData, 1);
            }
            UpdateQVW_ZUTEI(dwLocal);

        }
        public void InsertQVW_ZUTEI(DataRow dwData, int option = 1)
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1://20140501
                    or1.CommandText = "INSERT INTO QVW_ZUTEI  "
                        + " SELECT DISTINCT 'G' AS ARTST, ZUART AS PART,ZUVAR AS PVAR,ZUFARBE AS PCOLOR,'          ' AS PDESS,'          ' AS PDCWY,'          ' AS PFINISH,'       ' AS PSIZE,ZULO AS LO,ZULB AS LB,'V' AS AUFTYP,ZUAUFKRS AS PKRS,ZUAUFLFD AS PLFD,ZUAUFPOS AS PPOS,SUM(ZUEINTKG*0.001) AS STWEIGHT"
                        + " FROM ZUTEI B WHERE ZUMANDANT=:MANDANT "
                        +" GROUP BY ZUMANDANT,ZULO,ZULB,ZUART,ZUVAR,ZUFARBE,ZUAUFKRS,ZUAUFLFD,ZUAUFPOS";
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        }
        public void DeleteQVW_ZUTEI(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM QVW_ZUTEI X ";
                    break;  
                default:
                    break;
            }
            Connect2Proxy(or1);
        }
        public DataSet QueryQVW_ZUTEI(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "SELECT * FROM QVW_ZUTEI "; ;
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "QVW_ZUTEI";
            Return = Result;
            return Return;
        }
        public void UpdateQVW_ZUTEI(DataRow dwData, int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                default:
                    break;
            }
            Connect2Proxy(or1);
        }
    }
}
